//
//  BannerViewController.m
//  HZZFAdSDK_Example
//
//  Copyright © 2025 早范. All rights reserved.
//

#import "BannerViewController.h"
#import <HZZFAdSDK/HZZFAdSDKBannerAdView.h>
@interface BannerViewController ()<HZZFSDKBannerAdViewDelegate>
@property (nonatomic)HZZFAdSDKBannerAdView *bannerView;
@end

@implementation BannerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"banner";
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    CGFloat width = (self.view.frame.size.width - 150) / 2;
    btn.frame = CGRectMake(width, 100, 150, 40);
    
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.backgroundColor = [UIColor orangeColor];
    btn.layer.cornerRadius = 20;
    [self.view addSubview:btn];
    [btn setTitle:@"显示广告" forState:UIControlStateNormal];
//    [btn setTitleColor:[UIColor blackColor] forState:0];
    [btn addTarget:self action:@selector(loadBannerAd) forControlEvents:UIControlEventTouchUpInside];
}

- (void)loadBannerAd{
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIViewController *rvc = window.rootViewController;
    
    _bannerView = [[HZZFAdSDKBannerAdView alloc] initWithFrame:CGRectMake(self.view.center.x-150,self.view.center.y, 300,200)];
    _bannerView.delegate = self;
    _bannerView.controller = rvc;
    _bannerView.refershTime = 35;
    _bannerView.posId = @"10559905";
    _bannerView.customLoadingPage = YES;
    _bannerView.showCloseView = YES;
    // 查看价格，需要在设置广告位id之后调用
//    NSLog(@"price----%ld", [bannerView getBidPrice]);
    // 发送竞价失败上报，此时的价格为第三方赢价的价格
    // [_bannerView sendLossNotice:100];
    // 发送竞价成功上报
//    [bannerView sendWinNotice:100];
//    [_bannerView loadAndShow];
//    _bannerView.frame = CGRectMake(20, 200, 400, 100);
//    [rvc.view addSubview:_bannerView];
    [_bannerView loadAndShow];
}
/**
广告获取成功
@param bannerView banner实例
*/
- (void)HZZF_bannerViewDidReceived:(HZZFAdSDKBannerAdView *)bannerView{

    [self.view addSubview:self.bannerView];
}

/**
广告拉取失败
@param bannerView banner实例
@param error 错误描述
*/
- (void)HZZF_bannerViewFailToReceived:(HZZFAdSDKBannerAdView *)bannerView error:(NSError*)error{
    NSString *message = @"广告渲染失败了";
   
}
/**
广告点击
@param bannerView 广告实例
*/
- (void)HZZF_bannerViewClicked:(HZZFAdSDKBannerAdView *)bannerView loadingPageURL:(nonnull NSString *)loadingPageURL{

}

/**
广告关闭
@param bannerView 广告实例
*/
- (void)HZZF_bannerViewClose:(HZZFAdSDKBannerAdView *)bannerView{

}


/**
广告展示
@param bannerView 广告实例
*/
- (void)HZZF_bannerViewExposure:(HZZFAdSDKBannerAdView *)bannerView{

}

/**
关闭落地页
@param bannerView 广告实例
*/
- (void)HZZF_bannerAdCloseLandingPage:(nonnull HZZFAdSDKBannerAdView *)bannerView {
    
}


- (void)HZZF_bannerViewClickedReport:(nonnull HZZFAdSDKBannerAdView *)bannerView {
    
}


- (void)HZZF_bannerViewExposureReport:(nonnull HZZFAdSDKBannerAdView *)bannerView {
    
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
